package com.cskaoyan.market.service.wx.impl;

import com.cskaoyan.market.db.domain.MarketOrderExample;
import com.cskaoyan.market.db.mapper.MarketOrderMapper;
import com.cskaoyan.market.service.wx.WxUserService;
import com.cskaoyan.market.util.MarketConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName WxUserServiceImpl
 * @Description
 * @Author MZ
 * @Date 2023/5/24 14:42
 */
@Service
public class WxUserServiceImpl implements WxUserService {

    @Autowired
    MarketOrderMapper orderMapper;

    @Override
    public Map<String, Long> getUserIndex(Integer userId) {
        Map<String, Long> result = new HashMap<>();
        // 待收货 unrecv
        MarketOrderExample unrecvExample = new MarketOrderExample();
        unrecvExample.or().andDeletedEqualTo(false).andUserIdEqualTo(userId).andOrderStatusEqualTo(MarketConstant.HAVE_SHIPMENT);
        long unrecv = orderMapper.countByExample(unrecvExample);
        result.put("unrecv",unrecv);

        // 待评价 uncomment
        MarketOrderExample uncommentExample = new MarketOrderExample();
        List<Short> uncommentStatus = new ArrayList<>();
        uncommentStatus.add(MarketConstant.USER_RECEIPT);
        uncommentStatus.add(MarketConstant.SYSTEM_RECEIPT);
        uncommentExample.or().andDeletedEqualTo(false).andUserIdEqualTo(userId).andOrderStatusIn(uncommentStatus);
        long uncomment = orderMapper.countByExample(uncommentExample);
        result.put("uncomment",uncomment);

        // 待付款 unpaid
        MarketOrderExample unpaidExample = new MarketOrderExample();
        unpaidExample.or().andDeletedEqualTo(false).andUserIdEqualTo(userId).andOrderStatusEqualTo(MarketConstant.NO_PAYMENT);
        long unpaid = orderMapper.countByExample(unpaidExample);
        result.put("unpaid",unpaid);

        // 待发货 unship
        MarketOrderExample unshipExample = new MarketOrderExample();
        unshipExample.or().andDeletedEqualTo(false).andUserIdEqualTo(userId).andOrderStatusEqualTo(MarketConstant.HAVE_PAYMENT);
        long unship = orderMapper.countByExample(unshipExample);
        result.put("unship",unship);


        return result;
    }
}
